package com.gome.ocean.service.zookeeper.balancer;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.stereotype.Component;

@Component
public class RoundRobinLoadBalancer implements LoadBalancer {

    private final AtomicInteger index = new AtomicInteger(-1);

    @Override
    public String getService(List<String> services) {
        int ind = Math.abs(index.incrementAndGet() % services.size());
        return services.get(ind);
    }

}
